package com.ruoyi.wcf.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wcf.domain.WcfProductClass;
import com.ruoyi.wcf.service.IWcfProductClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品分类Controller
 *
 * @author WZP
 * @date 2022-04-02
 */
@RestController
@RequestMapping("/wcf/WcfProductClass")
public class WcfProductClassController extends BaseController
{
    @Autowired
    private IWcfProductClassService wcfProductClassService;

    /**
     * 查询产品分类列表
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfProductClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(WcfProductClass wcfProductClass)
    {
        startPage();
        List<WcfProductClass> list = wcfProductClassService.selectWcfProductClassList(wcfProductClass);
        return getDataTable(list);
    }

    /**
     * 导出产品分类列表
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfProductClass:export')")
    @Log(title = "产品分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WcfProductClass wcfProductClass)
    {
        List<WcfProductClass> list = wcfProductClassService.selectWcfProductClassList(wcfProductClass);
        ExcelUtil<WcfProductClass> util = new ExcelUtil<WcfProductClass>(WcfProductClass.class);
        return util.exportExcel(list, "产品分类数据");
    }

    /**
     * 获取产品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfProductClass:query')")
    @GetMapping(value = "/{classId}")
    public AjaxResult getInfo(@PathVariable("classId") Long classId)
    {
        return AjaxResult.success(wcfProductClassService.selectWcfProductClassByClassId(classId));
    }

    /**
     * 新增产品分类
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfProductClass:add')")
    @Log(title = "产品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WcfProductClass wcfProductClass)
    {
        return toAjax(wcfProductClassService.insertWcfProductClass(wcfProductClass));
    }

    /**
     * 修改产品分类
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfProductClass:edit')")
    @Log(title = "产品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WcfProductClass wcfProductClass)
    {
        return toAjax(wcfProductClassService.updateWcfProductClass(wcfProductClass));
    }

    /**
     * 删除产品分类
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfProductClass:remove')")
    @Log(title = "产品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classIds}")
    public AjaxResult remove(@PathVariable Long[] classIds)
    {
        return toAjax(wcfProductClassService.deleteWcfProductClassByClassIds(classIds));
    }

    /**
     * 查询产品分类列表-下拉框
     */
//    @PreAuthorize("@ss.hasPermi('wcf:WcfProductClass:list')")
    @GetMapping("/getList")
    public AjaxResult getList()
    {
        return AjaxResult.success(wcfProductClassService.getList());
    }

}
